/*
** clear.c for  in /home/renard/Dropbox/epitech/dev/projets/systemunix/zappy/zappy-2015-2014s-renard_g/serv-src
**
** Made by guillaume renard
** Login   <renard_g@epitech.net>
**
** Started on  Wed Jun 13 14:53:03 2012 guillaume renard
** Last update Thu Jul 19 17:27:27 2012 pierrick druart
*/

#include		<stdlib.h>

#include		"server.h"

void			clear_team(void *content)
{
  struct s_team		*team;

  team = (struct s_team *)content;
  if (team->name != NULL)
    free(team->name);
  if (team->egg != NULL)
  {
    team->egg->clear(team->egg, &free);
    free(team->egg);
  }
  free(content);
}

void			erase_event_mnt(void *content)
{
  free(content);
}

void			erase_client(void *content)
{
  struct s_client	*client;

  client = (struct s_client *)content;
  if (client->gamer != NULL)
  {
    client->gamer->task->clear(client->gamer->task, NULL);
    free(client->gamer->task);
    if (client->gamer->action_str != NULL)
      free(client->gamer->action_str);
    free(client->gamer);
    client->gamer = NULL;
  }
  if (client->send != NULL)
  {
    client->send->delete(client->send);
    client->send = NULL;
  }
  if (client->rcv != NULL)
  {
    client->rcv->delete(client->rcv);
    client->rcv = NULL;
  }
  free(content);
}

void			delete_game(t_game *game)
{
  game->team->clear(game->team, &clear_team);
  free(game->team);
  game->event->clear(game->event, NULL);
  free(game->event);
  game->event_mnt->clear(game->event_mnt, NULL);
  free(game->event_mnt);
  free(game);
}
